﻿<UserControl x:Class="FacebookClient.MessageNotificationsControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:FacebookClient="clr-namespace:FacebookClient"
    xmlns:ClientManager="clr-namespace:ClientManager" 
    xmlns:ClientManagerControls="clr-namespace:ClientManager.Controls"
    xmlns:Facebook="clr-namespace:Contigo;assembly=Contigo"
    MinWidth="250"
    x:Name="ThisControl">
  <UserControl.Resources>
    <FacebookClient:DateTimeToStringConverter x:Key="DateTimeConverter" />
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
  </UserControl.Resources>
  
  <Border Background="{DynamicResource ContentChromeBackground}" Padding="1" BorderThickness="1" BorderBrush="LightGray"
          Visibility="{Binding ElementName=ThisControl, Path=IsDisplayed, Converter={StaticResource BooleanToVisibilityConverter}}">
    <Grid>
      <StackPanel>
        <DockPanel>
          <Button DockPanel.Dock="Right" Margin="5" Content="0" Style="{StaticResource SimpleButtonStyle}" FontFamily="Webdings" Foreground="White" Command="{x:Static FacebookClient:MessageNotificationsControl.CloseCommand}" ToolTip="Hide messages" />
          <TextBlock Text="Inbox" Foreground="White" FontFamily="{DynamicResource SansSerifFont}" FontSize="{DynamicResource LargeFontSize1}" FontWeight="Bold" Margin="5" />
        </DockPanel>
        <StackPanel x:Name="ItemsPanel">
          <ItemsControl x:Name="MessageList" 
              Background="{DynamicResource PopupListControlBackgroundBrush}"
              Padding="5"
              ItemsSource="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=Inbox}">
            <ItemsControl.ItemTemplate>
              <DataTemplate DataType="{x:Type Facebook:MessageNotification}">
                <DockPanel Margin="0,0,0,5">
                  <Rectangle DockPanel.Dock="Top" 
                      Height="1" 
                      SnapsToDevicePixels="True" 
                      Width="240" 
                      VerticalAlignment="Top" 
                      HorizontalAlignment="Center" 
                      Fill="{DynamicResource NewsFeedItemDividerBrush}" />
                  <Grid>
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="50" />
                      <ColumnDefinition Width="150" />
                      <ColumnDefinition Width="300" />
                    </Grid.ColumnDefinitions>

                    <FacebookClient:FriendButton
                        Friend="{Binding Sender}" 
                        Style="{DynamicResource TinyFriendButtonStyle}"
                        Click="_OnFriendClicked"
                        VerticalAlignment="Top"
                        HorizontalAlignment="Left"/>

                    <StackPanel Grid.Column="1">
                      <TextBlock TextWrapping="Wrap" Style="{DynamicResource ProfileNameTextBlockStyle}" FontSize="{DynamicResource MiddleFontSize}">
                        <Hyperlink 
                            Command="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=NavigationCommands.NavigateToContentCommand}" 
                            CommandParameter="{Binding Sender}">
                          <Run Text="{Binding Sender.Name, Mode=OneWay}" />
                        </Hyperlink>
                      </TextBlock>

                      <TextBlock Grid.Column="1" Grid.Row="1" VerticalAlignment="Top" TextWrapping="Wrap" Style="{StaticResource CreatedTextBlockStyle}" Text="{Binding Updated, Converter={StaticResource DateTimeConverter}}"/>
                    </StackPanel>
                    
                    <StackPanel Grid.Column="2">
                      <TextBlock TextWrapping="Wrap" FontWeight="Bold" Style="{DynamicResource AttachmentTitleTextBlockStyle}" FontSize="{DynamicResource MiddleFontSize}">
                        <Hyperlink 
                            Command="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=NavigationCommands.NavigateToContentCommand}" 
                            CommandParameter="{Binding Link}">
                          <Run>
                            <Run.Style>
                              <Style TargetType="{x:Type Run}">
                                <Setter Property="Text" Value="{Binding Title, Mode=OneWay}"/>
                                <Style.Triggers>
                                  <DataTrigger Binding="{Binding Title}" Value="">
                                    <Setter Property="Text" Value="(No Subject)"/>
                                  </DataTrigger>
                                </Style.Triggers>
                              </Style>
                            </Run.Style>
                          </Run>
                        </Hyperlink>
                      </TextBlock>
                          
                      <TextBlock TextWrapping="Wrap" Style="{DynamicResource MessageTextBlockStyle}">
                        <FacebookClient:HyperlinkTextContent Text="{Binding Description}" RequestNavigate="_OnMessageRequestNavigate" Foreground="{DynamicResource NotificationMessageTextForeground}" />
                      </TextBlock>
                    </StackPanel>
                  </Grid>
                </DockPanel>
              </DataTemplate>
            </ItemsControl.ItemTemplate>
          </ItemsControl>
        </StackPanel>
        <Button x:Name="ShowInboxButton" 
            Margin="3,5" 
            Height="22" 
            HorizontalAlignment="Right" 
            VerticalAlignment="Top" 
            Click="ShowInboxButton_Click"
            Style="{DynamicResource StandardButtonStyle}">
          See Inbox
        </Button>
      </StackPanel>
    </Grid>
  </Border>
</UserControl>
